//
//  BigTableViewCell.m
//  TourPlay
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "BigTableViewCell.h"

@interface BigTableViewCell ()

@property (nonatomic, retain) UIImageView *titleImageV;
@property (nonatomic, retain) UIImageView *orgPhoto;
@property (nonatomic, retain) UILabel *orgNameL;
@property (nonatomic, retain) UILabel *titleL;
@property (nonatomic, retain) UILabel *timeL;
@property (nonatomic, retain) UILabel *addressL;

@property (nonatomic, retain) UILabel *watchL;
@property (nonatomic, retain) UILabel *likeL;
@end

@implementation BigTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    // 背景
    UIView *viewBack = [[UIView alloc] initWithFrame:CGRectMake(7, 0, SCREEN_WIDTH - 7 * 2, (SCREEN_HEIGHT - 44 - 49 - 64) / 1.15f - 7)];
    
    viewBack.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1.0];
    // 圆角
    viewBack.layer.cornerRadius = 4.f;
    [self.contentView addSubview:viewBack];
    [viewBack release];
    
    self.titleImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, viewBack.frame.size.width, viewBack.frame.size.height * 0.48f)];
    
    // 设置照片左上角和左下角为圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.titleImageV.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(2, 2)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.titleImageV.bounds;
    maskLayer.path = maskPath.CGPath;
    self.titleImageV.layer.mask = maskLayer;
    // 缩放模式
    self.titleImageV.contentMode = UIViewContentModeScaleAspectFill;
    
    [viewBack addSubview:self.titleImageV];
    [_titleImageV release];
    
    
    UIView *headViewBack = [[UIView alloc] initWithFrame:CGRectMake(15, self.titleImageV.frame.size.height - 15, 40, 40)];
    headViewBack.backgroundColor = viewBack.backgroundColor;
    // 裁掉边框
    headViewBack.layer.masksToBounds = YES;
    headViewBack.layer.cornerRadius = 20.f;
    [viewBack addSubview:headViewBack];
    [headViewBack release];
    
    
    self.orgPhoto = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, headViewBack.frame.size.width - 6, headViewBack.frame.size.height - 6)];
    // 裁掉边框
    self.orgPhoto.layer.masksToBounds = YES;
    self.orgPhoto.layer.cornerRadius = (headViewBack.frame.size.width - 6) / 2.f;
    [headViewBack addSubview:self.orgPhoto];
    [_orgPhoto release];
    
    
    self.orgNameL = [[UILabel alloc] initWithFrame:CGRectMake(headViewBack.frame.origin.x + headViewBack.frame.size.width + 10, self.titleImageV.frame.size.height, viewBack.frame.size.width - (headViewBack.frame.origin.x + headViewBack.frame.size.width) - 10, headViewBack.frame.size.height - 15)];
//    self.orgNameL.backgroundColor = [UIColor orangeColor];
    self.orgNameL.textColor = [UIColor colorWithRed:0.39 green:0.34 blue:0.35 alpha:1];
    self.orgNameL.font = [UIFont systemFontOfSize:12.5f];
    [viewBack addSubview:self.orgNameL];
    [_orgNameL release];
    
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(20, self.orgNameL.frame.origin.y + self.orgNameL.frame.size.height, viewBack.frame.size.width - 40, viewBack.frame.size.height * 0.2f)];
//    self.titleL.backgroundColor = [UIColor orangeColor];
    self.titleL.font = [UIFont systemFontOfSize:20.f];
    self.titleL.numberOfLines = 0;
    self.titleL.textAlignment = NSTextAlignmentCenter;
    [viewBack addSubview:self.titleL];
    [_titleL release];
    
    self.timeL = [[UILabel alloc] initWithFrame:CGRectMake(self.titleL.frame.origin.x, self.titleL.frame.origin.y + self.titleL.frame.size.height, self.titleL.frame.size.width, 20)];
//    self.timeL.backgroundColor = [UIColor orangeColor];
    self.timeL.textColor = [UIColor colorWithRed:0.71 green:0.69 blue:0.7 alpha:1];
    self.timeL.font = [UIFont systemFontOfSize:12.5f];
    self.timeL.textAlignment = NSTextAlignmentCenter;
    [viewBack addSubview:self.timeL];
    [_timeL release];
    
    self.addressL = [[UILabel alloc] initWithFrame:CGRectMake(self.timeL.frame.origin.x, self.timeL.frame.origin.y + self.timeL.frame.size.height, self.timeL.frame.size.width, self.timeL.frame.size.height)];
//    self.addressL.backgroundColor = [UIColor brownColor];
    self.addressL.font = [UIFont systemFontOfSize:13.5f];
    self.addressL.textColor = self.timeL.textColor;
    self.addressL.textAlignment = NSTextAlignmentCenter;
    [viewBack addSubview:self.addressL];
    [_addressL release];
    
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(20, viewBack.frame.size.height - 35, viewBack.frame.size.width - 40, 1)];
    lineView.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
    [viewBack addSubview:lineView];
    [lineView release];
    
    
    
    
    UIImageView *likeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(viewBack.frame.size.width - 21 - 25, lineView.frame.origin.y + 8 + 1, 18, 14)];
    likeImageV.image = [UIImage imageNamed:@"Indexnew_love@2x.png"];
    [viewBack addSubview:likeImageV];
    [likeImageV release];
    
    self.likeL = [[UILabel alloc] initWithFrame:CGRectMake(likeImageV.frame.origin.x + likeImageV.frame.size.width, likeImageV.frame.origin.y - 3, viewBack.frame.size.width - (likeImageV.frame.origin.x + likeImageV.frame.size.width) - 3, 18)];
    //    self.likeL.backgroundColor = [UIColor orangeColor];
    self.likeL.adjustsFontSizeToFitWidth = YES;
    self.likeL.textAlignment = NSTextAlignmentCenter;
    self.likeL.textColor = self.timeL.textColor;
    self.likeL.font = [UIFont systemFontOfSize:13.5f];
    [viewBack addSubview:self.likeL];
    [_likeL release];
    
    UIImageView *watchImageV = [[UIImageView alloc] initWithFrame:CGRectMake(likeImageV.frame.origin.x - likeImageV.frame.size.width - 50, likeImageV.frame.origin.y, likeImageV.frame.size.width, likeImageV.frame.size.height)];
    watchImageV.image = [UIImage imageNamed:@"Indexnew_eye@2x.png"];
    [viewBack addSubview:watchImageV];
    [watchImageV release];
    
    self.watchL = [[UILabel alloc] initWithFrame:CGRectMake(watchImageV.frame.origin.x + watchImageV.frame.size.width, self.likeL.frame.origin.y, likeImageV.frame.origin.x - (watchImageV.frame.origin.x + watchImageV.frame.size.width) - 5, self.likeL.frame.size.height)];
    //    self.watchL.backgroundColor = [UIColor orangeColor];
    self.watchL.adjustsFontSizeToFitWidth = YES;
    self.watchL.textAlignment = self.likeL.textAlignment;
    self.watchL.textColor = self.likeL.textColor;
    self.watchL.font = self.likeL.font;
    [viewBack addSubview:self.watchL];
    [_watchL release];

    // 夜间模式
    [self addColorChangedBlock:^{
        viewBack.nightBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        viewBack.normalBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        
        self.titleL.nightTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        self.titleL.normalTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        
        lineView.nightBackgroundColor = [ColorSingleton shareSingleton].cellLineColor;
        lineView.normalBackgroundColor = [ColorSingleton shareSingleton].cellLineColor;
        
    }];
    
}
- (void)setContentMod:(ContentMod *)contentMod
{
    if (_contentMod != contentMod) {
        [_contentMod release];
        _contentMod = [contentMod retain];
    }
    
    
    NSURL *url = [NSURL URLWithString:self.contentMod.pic];
    [self.titleImageV sd_setImageWithURL:url placeholderImage:PICHOLDEER];
    
    NSURL *urlOrg = [NSURL URLWithString:self.contentMod.orgavatar];
    [self.orgPhoto sd_setImageWithURL:urlOrg placeholderImage:[UIImage imageNamed:@"detail_touxiang@2x.png"]];
    
    self.orgNameL.text = self.contentMod.orgname;

    
    self.titleL.text = self.contentMod.title;
    
    self.timeL.text = self.contentMod.timestr;
    self.addressL.text = self.contentMod.address;
    
    self.watchL.text = [NSString stringWithFormat:@"%ld", self.contentMod.viewcount];
    self.likeL.text = [NSString stringWithFormat:@"%ld", self.contentMod.likercount];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
